/* Copyright (C) 1995 by Joseph J. Pfeiffer, Jr.
Use, redistribution, and modification of this code is permitted without
fee subject to the following conditions:

1.  Redistribution of this code must preserve this copyright notice.

2.  Binary distributions must include this notice and disclaimer.

3.  Advertising materials that refer to specific features of this
    product must acknowledge the author.

4.  The author's name may not be used to endorse or promote any
    product derived from this software without written permission.
*/
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFLEN 5
#define TICKNUM 32
unsigned char penbuf[BUFLEN];
char ticker[TICKNUM] = {'|', '|', '|', '|', '|', '|', '|', '|',
		        '/', '/', '/', '/', '/', '/', '/', '/',
		        '-', '-', '-', '-', '-', '-', '-', '-',
		        '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\'
};

main() {
    int fd, len, i, count;
    int readno = 0;

    count = 0;

    printf("Pen test started\n");

    fd = open("/dev/cpqpen2", O_RDONLY);
    printf("fd = %d\r", fd);
    if (fd < 0) {
        perror("open failed");
        exit(-1);
    }

    printf("pen open; looping on reads\n");

    while (1) {
        len = read(fd, penbuf, BUFLEN);
        if (len != BUFLEN) {
            perror("bad read");
            exit(-2);
		}
		
		printf("status = %02x, x = %5d,  y = %5d\r",
			   penbuf[0],
			   (penbuf[1] << 8) | penbuf[2],
			   (short) (penbuf[3] << 8) | penbuf[4]);
			   
	}
}

